﻿using Microsoft.Xna.Framework;

namespace BruteForce.Animation
{
    public class LinearMovementTransition : Transition
    {
        public Vector2 EndPosition;
        public Vector2 StartPosition;
        private Vector2 _nsteps;

        public LinearMovementTransition(double duration, Vector2 startPosition, Vector2 endPosition)
            : base(duration)
        {
            StartPosition = startPosition;
            EndPosition = endPosition;
        }

        public Vector2 CurrentPosition
        {
            get
            {
                return new Vector2((float) (StartPosition.X + _nsteps.X*Value),
                                   (float) (StartPosition.Y + _nsteps.Y*Value));
            }
        }

        public override void StartTransition()
        {
            _nsteps = new Vector2(EndPosition.X - StartPosition.X, EndPosition.Y - StartPosition.Y);
            base.StartTransition();
        }

        public override void Interpolate(GameTime time)
        {
            double t = Time/Duration;
            Value = t;
        }
    }
}